package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.AutoWired;
import com.lagou.edu.annotation.MyTransational;
import com.lagou.edu.annotation.Service;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
import org.springframework.beans.factory.annotation.Qualifier;


/**
 * @author 应癫
 */
@Service("transferService")
@MyTransational
public class TransferServiceImpl implements TransferService {

    @AutoWired
    private AccountDao accountDao;


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        Account from = accountDao.getAccountByCartId(fromCardNo);
        Account to = accountDao.getAccountByCartId(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccount(to);
            int c = 1/0;
        accountDao.updateAccount(from);


    }
}
